<template>
	<view class="wpprs">
		<uni-search-bar placeholder="请输入公司名称/类别/SN/品牌/仪器名称" v-model="keyword" bgColor="#fff" @confirm="search" />
		<view class="tabbox">
			<view @click="acw = 1">
				待接单
				<view v-if="acw == 1"><span></span></view>
			</view>
			<view @click="acw = 2">
				待处理
				<view v-if="acw == 2"><span></span></view>
			</view>
			<view @click="acw = 3">
				处理中
				<view v-if="acw == 3"><span></span></view>
			</view>
			<view @click="acw = 4">
				已解决
				<view v-if="acw == 4"><span></span></view>
			</view>
			<view @click="acw = 5">
				未解决
				<view v-if="acw == 5"><span></span></view>
			</view>
			<view @click="acw = 6">
				已拒绝
				<view v-if="acw == 6"><span></span></view>
			</view>
		</view>
		<imgEmpty v-if="orderList.length == 0"></imgEmpty>
		<view class="list" v-for="(item, idx) in orderList"><listItem :item="item" :status="acw" :type="true" :key="idx" @workOrderAccept="workOrderAccept"></listItem></view>
	</view>
</template>

<script>
import listItem from '@/components/listItem.vue';
import { engineerpage, workOrder, workOrderAccept } from '../../../api/order';
import imgEmpty from '../../../components/imgEmpty.vue';
export default {
	components: { listItem, imgEmpty },
	data() {
		return {
			acw: 1,
			workOrderType: null,
			keyword: '',
			orderList: []
		};
	},
	watch: {
		acw() {
			this.getList();
		}
	},
	onShow() {
		this.getList();
	},
	onHide() {},
	onLoad(e) {
		this.workOrderType = e.type;
		uni.setNavigationBarTitle({
			title: `我的${e.name}派单`
		});
		this.getList();
	},
	methods: {
		workOrderAccept(orderid) {
			if (!orderid) {
				return;
			}
			workOrderAccept(orderid).then((data) => {
				uni.showToast({
					title: '接单成功',
					duration: 2000
				});
				this.getList();
			});
		},
		getList() {
			this.orderList = [];
			if (this.acw > 3) {
				workOrder({
					type: this.workOrderType,
					status: this.acw,
					keyword: this.keyword,
					result: this.acw - 3
				}).then((data) => {
					this.orderList = data.content.list;
					setTabBarBadge(0, false);
				});
			} else {
				engineerpage({
					type: this.workOrderType,
					status: this.acw + 1,
					keyword: this.keyword
				}).then((data) => {
					this.orderList = data.content.list;
				});
			}
		},
		search(val) {
			this.getList();
		}
	}
};
</script>

<style lang="less" scoped>
.wpprs {
	background-color: #f1f1f1;
	height: 100%;
}
.tabbox {
	display: flex;
	font-size: 28upx;
	background-color: #fff;
	padding: 20upx 0;
	& > view {
		width: 125upx;
		line-height: 1;
		text-align: center;
		view {
			padding: 0;
			text-align: center;
			span {
				display: inline-block;
				background-color: red;
				width: 40upx;
				height: 5upx;
				border-radius: 4upx;
			}
		}
	}
}
.list {
	padding: 20upx;
}
</style>
